<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://struts.apache.org/tags-bean"  prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="/tags/c" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<script type="text/javascript">

    function grabar(){
       
        var jerObjFin=document.getElementById("txtJerObjFin").value;
        var fuentefin=document.getElementById("txtFueInfFin").value;
        var supuFin=document.getElementById("txtSupuFin").value;
        var codPrograma=document.getElementById("codPrograma").value;
        var opcion=document.getElementById("opcion").value;
        var codUpdate=document.getElementById("codUpdate").value;
             
        var idDiv = "divTabla";
        var metodo = "GET";
        var url = "consultasAjax/listarProgEstrFAjax.jsp?jerObjFin="+jerObjFin+"&fuentefin="+fuentefin+"&supuFin="+supuFin+"&codPrograma="+codPrograma+"&opcion="+opcion+"&codUpdate="+codUpdate;
        var cadenaSalida = "";
        var async = true;
        // alert(1);
        document.getElementById(idDiv).innerHTML;
        autoCompletarDiv(metodo,url,cadenaSalida,async,idDiv);
        document.getElementById("Insertar").value="Grabar";
        setControls();
               
    }

    function editar(CODPRG,FIN_DESC_PRG,FIN_FUENTE_PRG,FIN_SUPUESTO_PRG){
        // alert(CODPRG);
        document.getElementById("Insertar").value="Editar";

        document.getElementById("txtJerObjFin").value=FIN_DESC_PRG;
        document.getElementById("txtFueInfFin").value=FIN_FUENTE_PRG;
        document.getElementById("txtSupuFin").value=FIN_SUPUESTO_PRG;
        document.getElementById("codUpdate").value=CODPRG;
        document.getElementById("opcion").value=2;

    }
    function eliminar(CODPRG){


        document.getElementById("txtJerObjFin").value="";
        document.getElementById("txtFueInfFin").value="";
        document.getElementById("txtSupuFin").value="";
        document.getElementById("codUpdate").value=CODPRG;
        document.getElementById("opcion").value=3;
        //document.getElementById("codPrograma").value=0;

        grabar();

    }

    function validar(){

        if (document.getElementById("txtJerObjFin").value=="" ||document.getElementById("txtJerObjFin").value==null)
        {
            document.getElementById("txtJerObjFin").focus();
            alert("Ingrese Jerarquia Objetos ");
            return;
        }

        if (document.getElementById("txtFueInfFin").value=="" ||document.getElementById("txtFueInfFin").value==null)
        {
            alert("Ingrese Fuente ");
            document.getElementById("txtFueInfFin").focus();
            return;
        }

        if (document.getElementById("txtSupuFin").value=="" ||document.getElementById("txtSupuFin").value==null)
        {
            document.getElementById("txtSupuFin").focus();
            alert("Ingrese Supuesto ");
            return;
        }
        grabar();
    }

    function setControls(){
        document.getElementById("txtJerObjFin").value="";
        document.getElementById("txtFueInfFin").value="";
        document.getElementById("txtSupuFin").value="";
        //document.getElementById("codPrograma").value;
        document.getElementById("opcion").value=1;
        document.getElementById("codUpdate").value=0;

    }


    function autoCompletarDiv(metodo,url,cadena,async,idDiv)
    {
        if( window.XMLHttpRequest )
            ajax = new XMLHttpRequest();
        else
            ajax = new ActiveXObject("Microsoft.XMLHTTP");
        ELEMENT_DIV = idDiv;
        ajax.onreadystatechange = funcionCallbackVerDiv;
        ajax.open( metodo, url, async);
        ajax.send(cadena);
    }

    function funcionCallbackVerDiv()
    {
        if( ajax.readyState == 4 )
        {
            if( ajax.status == 200 )
            {
                document.getElementById(ELEMENT_DIV).innerHTML = ajax.responseText;
            }
        }
    }


    function meta(cod,desc){
        
        var codPrograma=document.getElementById("codPrograma").value;
        var descPrograma=document.getElementById("titu_programa").value;
        var form = document.getElementById("ProgEstrForm");
        //form.codObj.value = codigo;
        //form.descObj.value = desc;
        form.action="ProgEstra.do?dispatch=loadFinMeta&cod="+cod+"&desc="+desc+"&descPrograma="+descPrograma+"&codPrograma="+codPrograma;

        form.method="post";
        form.submit();
    }
    function regresar(){

        var form = document.getElementById("ProgEstrForm");
        form.action="ProgEstra.do?dispatch=load&titu_programa=";

        form.method="post";

        form.submit();

    }
</script>
<html >
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="lib/css/estilos.css" type="text/css">
        <link href="lib/css/calendar.css" rel="stylesheet" type="text/css" />
        <link href="lib/css/styles_pages.css" rel="stylesheet" type="text/css" />
        <title>JSP Page</title>
    </head>

    <body>
        <center>
            <h1>Fin de Programa Estrat&eacute;gico</h1>
        </center>
        <html:form action="ProgEstra.do?dispatch=loadMeta" styleId="ProgEstrForm">
            <html:hidden property="codPrograma" styleId="codPrograma" />
            <input type="hidden" id="opcion" value="1">
            <input type="hidden" id="codUpdate" value="0">
            <table>
                <tr>
                    <td>
                        Nombre de Programa
                    </td>
                    <td>
                        <html:text property="titu_programa" styleId="titu_programa" />
                    </td>
                </tr>
            </table>


            <table border="1"  align="center">
                <tr>
                    <td>Fin</td>
                    <td><input type="text" name="txtJerObjFin" id="txtJerObjFin" /></td>
                </tr>
                <tr>
                    <td>Fuente de Informaci&oacute;n</td>
                    <td><input type="text" name="txtFueInfFin" id="txtFueInfFin" /></td>
                </tr>
                <tr>
                    <td>Supuesto</td>
                    <td><input type="text" name="txtSupuFin" id="txtSupuFin" /></td>
                </tr>
            </table>
            <table width="100%">
                <tr>
                    <td colspan="2" align="center">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                        <input id="Insertar" name="Insertar" type="button" value="Grabar" onclick="validar()"/><html:button property="button"  value="regresar" onclick="regresar()" />
                    </td>
                </tr>
            </table>
            <%int i = 1;%>
            <table>
                <tr>
                    <td colspan="2">
                        <!-- Ini Ingreso del Marco Logico-->



                        <logic:present name="ProgEstrForm" property="listDetalleMarcoLogicoFin">

                            <div id="divTabla">

                                <table id="tablaFin" width="100%" align="right" class="userTable">
                                    <tr class="even" align="center">
                                        <th class="textoTR">#</th>                                        
                                        <th class="textoTR">Fin </th>
                                        <th class="textoTR">Fuente</th>
                                        <th class="textoTR">Supuesto</th>
                                        <th class="textoTR">Editar</th>
                                        <th class="textoTR">Eliminar</th>
                                        <th class="textoTR">Meta</th>

                                    </tr>

                                    <logic:iterate name="ProgEstrForm" property="listDetalleMarcoLogicoFin" id="lista">
                                        <tr align="center">
                                            <td width="10%" align="center">
                                                <%= i++%>
                                            </td>
                                            <td width="10%" align="center">
                                                <bean:write name="lista" property="FIN_DESC_PRG"/>
                                            </td>

                                            <td width="10%" align="center">
                                                <bean:write name="lista" property="FIN_FUENTE_PRG"/>
                                            </td>

                                            <td width="10%" align="center">
                                                <bean:write name="lista" property="FIN_SUPUESTO_PRG"/>
                                            </td>

                                            <td width="10%" align="center">

                                                <img style="cursor:pointer" title="Editar" alt="Editar" border=0  src="images/b_edit.png"
                                                     onclick="editar(
                                                         '<c:out value="${lista.FIN_COD_PRG}"/>',
                                                         '<c:out value="${lista.FIN_DESC_PRG}"/>',
                                                         '<c:out value="${lista.FIN_FUENTE_PRG}"/>',
                                                         '<c:out value="${lista.FIN_SUPUESTO_PRG}"/>'
                                                     );"/>

                                            </td>

                                            <td width="10%" align="center">

                                                <img style="cursor:pointer" title="Eliminar" title="Eliminar" alt="Eliminar" border=0  src="images/b_drop.png"
                                                     onclick="eliminar('<c:out value="${lista.FIN_COD_PRG}"/>');">
                                            </td>

                                            <td width="20%" align="center">

                                                <img style="cursor:pointer" title="MarcoLogico" title="Meta" alt="Meta" border=0  src="images/file_preview.png"
                                                     onclick = "meta('<c:out value="${lista.FIN_COD_PRG}"/>','<c:out value="${lista.FIN_DESC_PRG}"/>');">
                                            </td>




                                        </tr>
                                    </logic:iterate>
                                </table>


                            </div>
                        </logic:present>
                       
                              <!-- Fin Ingreso del Marco Logico-->
                    </td>
                </tr>
            </table>
        </html:form>
    </body>
</html>

